package com.api.interfaces;

import org.apache.http.Header;

import com.api.utils.GetMethod;
import com.api.utils.JsonHelp;

public class LoginInterface {

	/**
	 * 获取登录后的cookie
	 * 
	 * @param openid
	 * @return
	 */
	public static String getCookie(String mobile) {
		String cookie = "";
		// 登录接口
		String loginurl = "http://xxx.xxx.com/test/memberlogin?openid=" + getOpenid(mobile);
		Header[] header = GetMethod.getHeader(loginurl);
		for (int i = 0; i < header.length; i++) {
			if (header[i].getName().equals("Set-Cookie")) {
				cookie = header[i].getValue();
			}
		}
		return cookie;
	}

	/**
	 * 获取用户的openid
	 * 
	 * @param mobile
	 * @return
	 */
	public static String getOpenid(String mobile) {
		// 登录接口
		String loginurl = "http://xxx.xxx.com/member/login?action=mobileLogin&mobile=" + mobile + "&code=123456";
		String result = GetMethod.doGetCookie(loginurl, "");
		return JsonHelp.getJsonValue(JsonHelp.getJsonValue(result, "result"), "openid");
	}

}
